package model;

import connection.DbConnection;
import bean.Question;

import java.sql.*;

public class CreateSQuestionImpl {
	
	
	/**
	 * Sets all PollUser javabean attributes from database (even if empty in database).
	 * 
	 * @param user is PollUser bean
	 */
			private static PreparedStatement st;
			private static Connection conn;
			private static ResultSet rs;
				
			public void createquestion(Question question){
				
				
				try{
					conn = new DbConnection().getConn();
					System.out.println("*****//RESULTSET NEXT");
					st = conn.prepareStatement("insert into Question (text, status, TemplateQuestion, correct1, correct2, correct3, correct4, correct5, numberonly, lowest, highest, font, fontsize, color, timer, rescounter, cai) values ('?',?,?,'?','?','?','?','?',?,?,?,'?',?,'?',?,'?','?')");
					
					st.setString(1, question.getText());
					st.setInt(2, 0);
					st.setInt(3, question.getTemplateQuestion());
					if(question.getCorrect1() == null){
						st.setString(4, "null");
					}else{
						st.setString(4, question.getCorrect1());
					}
					if(question.getCorrect2() == null){
						st.setString(5, question.getCorrect2());
					}else{
						st.setString(5, "null");
					}
					if(question.getCorrect3() == null){
						st.setString(6, question.getCorrect3());
					}else{
						st.setString(6, "null");
					}
					if(question.getCorrect4() == null){
						st.setString(7, question.getCorrect4());
					}else{
						st.setString(7, "null");
					}
					if(question.getCorrect5() == null){
						st.setString(8, question.getCorrect5());
					}else{
						st.setString(8, "null");
					}
					st.setInt(9, question.getNumberOnly());
					st.setDouble(10, question.getLowest());
					st.setDouble(11, question.getHighest());
					st.setString(12, question.getFont());
					st.setInt(13, question.getFontSize());
					st.setString(14, question.getColor());
					st.setInt(15, Integer.parseInt(question.getTimer()));
					st.setString(16, question.getResCounter());
					st.setString(17, question.getCAI());
					st.executeQuery();
				}catch(Exception e){
					e.printStackTrace();
				}
			}
}